Open
Conversation
Adds the WebSocket module to the Node platform allowing Gren programs to create WebSocket servers and handle client connections.
robinheghan
reviewed
Feb 14, 2026
| Ok server -> | ||
| { model = { model | server = Just server } | ||
| , command = | ||
| Stream.writeLineAsBytes "WebSocket server started on port 8085" model.stdout |
Member
There was a problem hiding this comment.
You can simplify these staments with the Stream.Log module.
| ws.on("message", (data, isBinary) => { | ||
| const entry = { data, isBinary }; | ||
| if (waitingForMessageQueue.length > 0) { | ||
| waitingForMessageQueue.shift()(entry); |
| // Each handler reads the current reference from wss on every event fire, | ||
| // so re-evaluating subscriptions updates behavior for existing connections. | ||
| ws.on("message", function (data, isBinary) { | ||
| var handlers = wss.__grenMessageHandlers; |
Member
There was a problem hiding this comment.
would it be better to rename wss to server and ws to client? The names are easy to mix up as it currently stands.
|
|
||
| {-| Convert a [`ConnectionId`](WebSocketServer.ConnectionId) to an `Int`. | ||
|
|
||
| Useful for storing connections in a `Dict Int Connection`. |
Member
There was a problem hiding this comment.
Can't we just expose ConnectionId as Int instead of it being a opaque type? 🤔
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds WebSocket server capabilities.
This is mostly modeled after the HttpServer module. There are tests but I haven't integrated it into a real application yet (going to work on gren-lang/browser#101 next so I have both parts to test with).